{% extends "base.html" %}

{% block title %}学生管理{% endblock %}
{% block page_title %}{{ class_id }}班学生管理{% endblock %}

{% block content %}
<!-- 添加学生表单 -->
<div class="card mb-4">
    <div class="card-header">
        <i class="fas fa-user-plus me-2"></i>添加学生
    </div>
    <div class="card-body">
        <form method="post">
            {% csrf_token %}
            <div class="input-group">
                <input type="text" name="new_name" placeholder="输入学生姓名" required 
                       class="form-control form-control-lg">
                <button type="submit" name="add_student" class="btn btn-primary">
                    <i class="fas fa-plus me-1"></i>添加学生
                </button>
            </div>
        </form>
    </div>
</div>

<!-- 学生列表 -->
<div class="card">
    <div class="card-header d-flex justify-content-between align-items-center">
        <span><i class="fas fa-users me-2"></i>学生列表</span>
        <span class="badge bg-primary rounded-pill">{{ students|length }}</span>
    </div>
    <div class="card-body">
        {% if students %}
        <div class="list-group">
            {% for student in students %}
            <div class="list-group-item d-flex justify-content-between align-items-center">
                <form method="post" class="d-flex w-100 align-items-center">
                    {% csrf_token %}
                    <input type="hidden" name="old_name" value="{{ student }}">
                    <input type="text" name="new_name" value="{{ student }}" 
                           class="form-control border-0 bg-transparent fs-5" 
                           style="flex: 1; max-width: 70%;">
                    <div class="btn-group ms-auto">
                        <button type="submit" name="edit_student" 
                                class="btn btn-sm btn-outline-warning me-1">
                            <i class="fas fa-save me-1"></i>保存
                        </button>
                        <button type="submit" name="delete_student" 
                                class="btn btn-sm btn-outline-danger"
                                onclick="return confirm('确定删除该学生吗？')">
                            <i class="fas fa-trash-alt me-1"></i>删除
                        </button>
                    </div>
                </form>
            </div>
            {% endfor %}
        </div>
        {% else %}
        <div class="text-center py-5">
            <i class="fas fa-user-slash fa-3x text-muted mb-3"></i>
            <h5>暂无学生数据</h5>
            <p class="text-muted">请添加学生</p>
        </div>
        {% endif %}
    </div>
</div>
{% endblock %}